Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / app / src / main / java / com / geeksville / mesh / util / Utf8ByteLengthFilter.java

Displaying Raw • Download

app/src/main/java/com/geeksville/mesh/util/Utf8ByteLengthFilter.java 1c3784235e7e20ed88e054097d2e7addbff92dc3 (1c378423) Text, 2.67 KB

T8b949e/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Tff7b72package T7ee787com.geeksville.mesh.utilTb4b4b4;

Tff7b72import T7ee787android.text.InputFilterTb4b4b4;
Tff7b72import T7ee787android.text.SpannedTb4b4b4;

T8b949e/**
* This filter will constrain edits so that the text length is not
* greater than the specified number of bytes using UTF-8 encoding.
*/
Tff7b72public Tff7b72class T56d364Utf8ByteLengthFilter Tff7b72implements Te6edf3InputFilter Tb4b4b4{
Tff7b72private Tff7b72final Tffa657int Te6edf3mMaxBytesTb4b4b4;
Tff7b72public Td2a8ffUtf8ByteLengthFilterTb4b4b4(Tffa657int Te6edf3maxBytesTb4b4b4) Tb4b4b4{
Te6edf3mMaxBytes Tff7b72= Te6edf3maxBytesTb4b4b4;
Tb4b4b4}
Tff7b72public Te6edf3CharSequence Td2a8fffilterTb4b4b4(Te6edf3CharSequence Te6edf3sourceTb4b4b4, Tffa657int Te6edf3startTb4b4b4, Tffa657int Te6edf3endTb4b4b4,
Te6edf3Spanned Te6edf3destTb4b4b4, Tffa657int Te6edf3dstartTb4b4b4, Tffa657int Te6edf3dendTb4b4b4) Tb4b4b4{
Tffa657int Te6edf3srcByteCount Tff7b72= T79c0ff0Tb4b4b4;
T8b949e// count UTF-8 bytes in source substring
Tff7b72for Tb4b4b4(Tffa657int Te6edf3i Tff7b72= Te6edf3startTb4b4b4; Te6edf3i Tff7b72< Te6edf3endTb4b4b4; Te6edf3iTff7b72+Tff7b72+Tb4b4b4) Tb4b4b4{
Tffa657char Te6edf3c Tff7b72= Te6edf3sourceTb4b4b4.Te6edf3charAtTb4b4b4(Te6edf3iTb4b4b4)Tb4b4b4;
Te6edf3srcByteCount Tff7b72+Tff7b72= Tb4b4b4(Te6edf3c Tff7b72< Tb4b4b4(Tffa657charTb4b4b4) T79c0ff0x0080Tb4b4b4) Tff7b72? T79c0ff1 Tb4b4b4: Tb4b4b4(Te6edf3c Tff7b72< Tb4b4b4(Tffa657charTb4b4b4) T79c0ff0x0800 Tff7b72? T79c0ff2 Tb4b4b4: T79c0ff3Tb4b4b4)Tb4b4b4;
Tb4b4b4}
Tffa657int Te6edf3destLen Tff7b72= Te6edf3destTb4b4b4.Te6edf3lengthTb4b4b4(Tb4b4b4)Tb4b4b4;
Tffa657int Te6edf3destByteCount Tff7b72= T79c0ff0Tb4b4b4;
T8b949e// count UTF-8 bytes in destination excluding replaced section
Tff7b72for Tb4b4b4(Tffa657int Te6edf3i Tff7b72= T79c0ff0Tb4b4b4; Te6edf3i Tff7b72< Te6edf3destLenTb4b4b4; Te6edf3iTff7b72+Tff7b72+Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3i Tff7b72< Te6edf3dstart Tff7b72|Tff7b72| Te6edf3i Tff7b72>Tff7b72= Te6edf3dendTb4b4b4) Tb4b4b4{
Tffa657char Te6edf3c Tff7b72= Te6edf3destTb4b4b4.Te6edf3charAtTb4b4b4(Te6edf3iTb4b4b4)Tb4b4b4;
Te6edf3destByteCount Tff7b72+Tff7b72= Tb4b4b4(Te6edf3c Tff7b72< Tb4b4b4(Tffa657charTb4b4b4) T79c0ff0x0080Tb4b4b4) Tff7b72? T79c0ff1 Tb4b4b4: Tb4b4b4(Te6edf3c Tff7b72< Tb4b4b4(Tffa657charTb4b4b4) T79c0ff0x0800 Tff7b72? T79c0ff2 Tb4b4b4: T79c0ff3Tb4b4b4)Tb4b4b4;
Tb4b4b4}
Tb4b4b4}
Tffa657int Te6edf3keepBytes Tff7b72= Te6edf3mMaxBytes Tff7b72- Te6edf3destByteCountTb4b4b4;
Tff7b72if Tb4b4b4(Te6edf3keepBytes Tff7b72<Tff7b72= T79c0ff0Tb4b4b4) Tb4b4b4{
Tff7b72return Ta5d6ff"Ta5d6ff"Tb4b4b4;
Tb4b4b4} Tff7b72else Tff7b72if Tb4b4b4(Te6edf3keepBytes Tff7b72>Tff7b72= Te6edf3srcByteCountTb4b4b4) Tb4b4b4{
Tff7b72return Tff7b72nullTb4b4b4; T8b949e// use original dest string
Tb4b4b4} Tff7b72else Tb4b4b4{
T8b949e// find end position of largest sequence that fits in keepBytes
Tff7b72for Tb4b4b4(Tffa657int Te6edf3i Tff7b72= Te6edf3startTb4b4b4; Te6edf3i Tff7b72< Te6edf3endTb4b4b4; Te6edf3iTff7b72+Tff7b72+Tb4b4b4) Tb4b4b4{
Tffa657char Te6edf3c Tff7b72= Te6edf3sourceTb4b4b4.Te6edf3charAtTb4b4b4(Te6edf3iTb4b4b4)Tb4b4b4;
Te6edf3keepBytes Tff7b72-Tff7b72= Tb4b4b4(Te6edf3c Tff7b72< Tb4b4b4(Tffa657charTb4b4b4) T79c0ff0x0080Tb4b4b4) Tff7b72? T79c0ff1 Tb4b4b4: Tb4b4b4(Te6edf3c Tff7b72< Tb4b4b4(Tffa657charTb4b4b4) T79c0ff0x0800 Tff7b72? T79c0ff2 Tb4b4b4: T79c0ff3Tb4b4b4)Tb4b4b4;
Tff7b72if Tb4b4b4(Te6edf3keepBytes Tff7b72< T79c0ff0Tb4b4b4) Tb4b4b4{
Tff7b72return Te6edf3sourceTb4b4b4.Te6edf3subSequenceTb4b4b4(Te6edf3startTb4b4b4, Te6edf3iTb4b4b4)Tb4b4b4;
Tb4b4b4}
Tb4b4b4}
T8b949e// If the entire substring fits, we should have returned null
T8b949e// above, so this line should not be reached. If for some
T8b949e// reason it is, return null to use the original dest string.
Tff7b72return Tff7b72nullTb4b4b4;
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.05s